package structure.flyweight;

import java.util.HashMap;

/**
 * Created by lie on 2017/11/2.
 * 这里做了具体goods的缓存
 */
public class GoodsFactory {

    private static HashMap<String,PhoneGoods> pool = new HashMap<>();

    public static PhoneGoods getPhoneGoods(String name){
        if (pool.containsKey(name)) {
            System.out.println("使用缓存,key为：name = " + name);
            return pool.get(name);
        }else {
            PhoneGoods phoneGoods = new PhoneGoods(name);
            System.out.println("创建新phoneGoods对象,key为：name = " + name);
            pool.put(name,phoneGoods);
            return phoneGoods;
        }


    }
}
